package org.easy.wechatpay;


import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({WechatPayProperties.class})
@ConditionalOnProperty(prefix = WechatPayProperties.PREFIX, name = "enabled", havingValue = "true")
@AllArgsConstructor
public class WechatPayAutoConfiguration {

    private final WechatPayProperties properties;

    @Bean
    public WechatPayTemplate wechatPayTemplate() {
//        RSAAutoCertificateConfig config = new RSAAutoCertificateConfig.Builder()
//                .merchantId(properties.getMchId())
//                // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥，商户私钥会用来生成请求的签名
//                .privateKeyFromPath(properties.getKeyPath())
//                .merchantSerialNumber(properties.getMerchantSerialNumber())
//                .apiV3Key(properties.getApiV3Key())
//                .build();

        return new WechatPayTemplate(null, properties);
    }


}
